/*
2021-8-5
https://www.acwing.com/problem/content/3796/
*/
#include<iostream>
#include<algorithm>

using namespace std;
const int N=105;
int a[N];

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a,a+n);
        int res=0;
        for(int i=0;i<m;i++)
        {
            if(a[i]<0) res-=a[i];
            else break;
        }
        cout<<res<<endl;
    }
    return 0;
}
